// ==UserScript==
// @name         增强思否 (SegmentFault) 前端体验
// @namespace    https://segmentfault.com/u/jamesfancy
// @version      {{version}}
// @description  对思否社区的样式进行细节上的改善，支持 Chrome 77 及以上版本的浏览器。这是整合了问答和博客以及样式调整的脚本。
// @author       James Fan
// @license      MulanPSL-2.0
// @match        https://segmentfault.com/*
// @icon         https://cdn.segmentfault.com/r-e5cb5889/favicon.ico
// @grant        none
// ==/UserScript==

import improveAnswer from "./answer/index.js";
import improveStyle from "./styles/index.js";

const policies = [
    ["/q/", improveAnswer, "segmentfault.com/q/: improve answer"],
    [, improveStyle, "global: improve styles"],
].map(([rule, ...rest]) => {
    switch (typeof (rule)) {
        case "function":
            return [rule, ...rest];
        case "string":
            return [
                () => window.location.pathname.startsWith(rule),
                ...rest
            ];
        case "boolean":
            return [() => !!rule, ...rest];
        case "undefined":
            return [() => true, ...rest];
    }
});

policies.filter(([rule]) => rule()).forEach(([, fn, info]) => {
    (console.info ?? console.log)("[SF-MONKEY]", info);
    return fn();
});